
package com.zjxd.business.web.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.zjxd.business.web.api.filter.CrossFilter;
import com.zjxd.business.web.interceptor.ParameterValidateInterceptor;

/**
 * 拦截器配置
 * 
 * @author QIk
 */
@Configuration
public class InterceptoConfig extends WebMvcConfigurerAdapter {

	@Override
	public void addInterceptors(InterceptorRegistry registry) {

		// 参数验证拦截器
		InterceptorRegistration ir = registry.addInterceptor(new ParameterValidateInterceptor());
		// 需要拦截路径
		// ir.addPathPatterns("/**");
		// 不需要拦截路径
		// ir.excludePathPatterns("/api/key/getKey");
		ir.excludePathPatterns("/**");

	}

	@Bean
	public FilterRegistrationBean testFilterRegistration() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		registration.setFilter(new CrossFilter());// 添加过滤器
		registration.addUrlPatterns("/*");// 设置过滤路径，/*所有路径
		registration.setName("CrossFilter");// 设置优先级
		registration.setOrder(1);// 设置优先级
		return registration;
	}
}
